var g = Graphics.createArrayBuffer(32,12,8);
g.dump = _=>{
  var s = "";
  var b = new Uint8Array(g.buffer);
  var n = 0;
  for (var y=0;y<g.getHeight();y++) {
    s+="\n";
    for (var x=0;x<g.getWidth();x++) 
      s+=".#"[b[n++]?1:0];
  }
  return s;
}
g.print = _=>{
  print("`"+g.dump()+"`");
}
var ok = true;
function SHOULD_BE(a) {
  var b = g.dump();
  if (a!=b) {
    console.log("GOT :"+b+"\nSHOULD BE:"+a+"\n================");
    ok = false;
  }
}

// left align
g.clear(1).setFontAlign(-1,-1).drawString("HI\nWORLD",0,0);
SHOULD_BE(`
#.#.###.........................
#.#..#..........................
###..#..........................
#.#..#..........................
#.#.###.........................
................................
#.#..#..##..#...##..............
#.#.#.#.#.#.#...#.#.............
###.#.#.#.#.#...#.#.............
###.#.#.##..#...#.#.............
#.#..#..#.#.###.##..............
................................`);

// right align
g.clear(1).setFontAlign(1,-1).drawString("HI\nWORLD",31,0);
SHOULD_BE(`
.......................#.#.###..
.......................#.#..#...
.......................###..#...
.......................#.#..#...
.......................#.#.###..
................................
...........#.#..#..##..#...##...
...........#.#.#.#.#.#.#...#.#..
...........###.#.#.#.#.#...#.#..
...........###.#.#.##..#...#.#..
...........#.#..#..#.#.###.##...
................................`);

// center align
g.clear(1).setFontAlign(0,-1).drawString("HI\nWORLD",16,0);
SHOULD_BE(`
............#.#.###.............
............#.#..#..............
............###..#..............
............#.#..#..............
............#.#.###.............
................................
......#.#..#..##..#...##........
......#.#.#.#.#.#.#...#.#.......
......###.#.#.#.#.#...#.#.......
......###.#.#.##..#...#.#.......
......#.#..#..#.#.###.##........
................................`);

// center vertical align
g.clear(1).setFontAlign(0,0).drawString("HI\nWORLD",16,6);
SHOULD_BE(`
............#.#.###.............
............#.#..#..............
............###..#..............
............#.#..#..............
............#.#.###.............
................................
......#.#..#..##..#...##........
......#.#.#.#.#.#.#...#.#.......
......###.#.#.#.#.#...#.#.......
......###.#.#.##..#...#.#.......
......#.#..#..#.#.###.##........
................................`);



result = ok;
